
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.sound.sampled.AudioSystem;

import javazoom.jl.player.Player;

/**
 *
 * @author shaines
 */
public class MP3Player {

 private Player player;
 private InputStream is;
 
 /** Creates a new instance of MP3Player */
 public MP3Player( String filename ) 
 {
  try
  {
   // Create an InputStream to the file
   is = new FileInputStream( filename );
  }
  catch( Exception e )
  {
   e.printStackTrace();
  }
 }
 
 public MP3Player( URL url ) 
 {
  try
  {
   // Create an InputStream to the file
	  // remote via http
	  is = AudioSystem.getAudioInputStream(url);
	  // local
	  //is = url.openStream();
  }
  catch( Exception e )
  {
   e.printStackTrace();
  }
 }
 
 public void play()
 {
  try
  {
   player = new Player( is );
   
   PlayerThread pt = new PlayerThread();
  
   pt.start();
   while( !player.isComplete() )
   {
    int position = player.getPosition();
    
    System.out.println( "Position: " + position );
    try
    {
     Thread.sleep( 1000 );
    }
    catch( Exception ee )
    {
     ee.printStackTrace();
    }
   }
  }
  catch( Exception e )
  {
   e.printStackTrace();
  }
 }
 
 class PlayerThread extends Thread
 {
  public void run()
  {
   try
   {
    player.play();
   }
   catch( Exception e )
   {
    e.printStackTrace();
   }
  }
 }
 
 
 public static void main( String[] args )
 {
  
  
  MP3Player mp3Player;
try {
	URL resource = MP3Player.class.getResource("Freunde.mp3");
	mp3Player = new MP3Player( resource );
	mp3Player.play();
} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
  
 }}